package uk.ac.rothamsted.utils;

import java.io.Serializable;
import java.util.Arrays;

/**
 * @author lysenkoa
 *         Arrays as hash keys.
 */
public class ArrayKey<T extends Object> implements  Serializable {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private T[] array = null;

    /**
     *
     */
    public ArrayKey() {
    }

    /**
     * @param array
     */
    public ArrayKey(T[] array) {
        this.array = array;
    }
    
    public ArrayKey(T var){
    	this.array[0] = var;
    	this.array[1] = var;
    }

    /**
     * @return
     */
    public T[] getArray() {
        return array;
    }    

    /**
     * @param array
     */
    public void setArray(T[] array) {
        this.array = array;
    }
    

    @Override
    public int hashCode() {
        return Arrays.hashCode(array);
    }

    /**
     * @return
     */
    public int size() {
        return array.length;
    }

    @Override
    public boolean equals(Object key) {
        return key instanceof ArrayKey && Arrays.equals(array, ((ArrayKey<?>) key).getArray());
    }
    
    @Override
    public String toString(){
    	String output = "";
    	for(T i: array){
    		output += i + "\t";
    	}
    	output = output.substring(0, output.length() - 1);
    	return output;
    }
}
